home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performBoundary.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  16.4 KB  |  614 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Mar 14, 1997
  22. //
  23. //  Description:
  24. //      This script is defines the option box for the boundary  menu item.
  25. //
  26.  
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. proc setOptionVars(int $forceFactorySettings)
  42. {
  43.     if ($forceFactorySettings || !`optionVar -exists boundaryOrder`) {
  44.         optionVar -intValue boundaryOrder 0;
  45.     }
  46.     if ($forceFactorySettings || !`optionVar -exists boundaryInsist`) {
  47.         optionVar -intValue boundaryInsist 0;
  48.     }
  49.     if ($forceFactorySettings || !`optionVar -exists boundaryPartial`){
  50.         optionVar -intValue boundaryPartial 0;
  51.     }
  52.     if ($forceFactorySettings || !`optionVar -exists boundaryPolys`){
  53.         optionVar -intValue boundaryPolys 0;
  54.     }
  55.     if ($forceFactorySettings ||
  56.         !`optionVar -exists boundaryUseGlobal`) {
  57.         optionVar -intValue boundaryUseGlobal 1;
  58.     }
  59.     if ($forceFactorySettings || 
  60.         !`optionVar -exists boundaryTolerance`) {
  61.         optionVar -floatValue boundaryTolerance 0.01;
  62.     }
  63.     if ($forceFactorySettings || 
  64.         !`optionVar -exists boundaryAutoEdgeCount`) {
  65.         optionVar -iv boundaryAutoEdgeCount 4;
  66.     }
  67. }
  68.  
  69. //
  70. //  Procedure Name:
  71. //      boundaryVisibility
  72. //
  73. //  Description:
  74. //        Depending on the options, some other options do or do not show.
  75. //
  76. //  Input Arguments:
  77. //      parent               - Top level parent layout of the option box UI.
  78. //                             Required so that UI object names can be 
  79. //                             successfully resolved.
  80. //  Return Value:
  81. //      None.
  82. //
  83.  
  84. global proc boundaryVisibility( string $parent,
  85.                                 int $useGlobal,
  86.                                 int $insist,
  87.                                 string $goToTool)
  88. {
  89.     if( $useGlobal < 0 ) {
  90.         $useGlobal = 2 - `radioButtonGrp -q -select useGlobalRadio`;
  91.     }
  92.     if( $insist < 0 ) {
  93.         $insist = `radioButtonGrp -q -select insistRadio` - 1;
  94.     }
  95.  
  96.     if( $insist ) {
  97.         radioButtonGrp -e -en 1 useGlobalRadio;
  98.         if( $useGlobal == 1 ) {
  99.             floatSliderGrp -e -en 0 toleranceFloat;
  100.         }
  101.         else {
  102.             floatSliderGrp -e -en 1 toleranceFloat;
  103.         }
  104.     }
  105.     else {
  106.         radioButtonGrp -e -en 0 useGlobalRadio;
  107.         floatSliderGrp -e -en 0 toleranceFloat;
  108.     }
  109.  
  110.     if( "" != $goToTool ) {
  111.         checkBoxGrp -e -en1 `scriptCtx -q -lac $goToTool`
  112.           scriptToolExtraWidget2;
  113.     }
  114. }
  115.  
  116. //
  117. //  Procedure Name:
  118. //      boundarySetup
  119. //
  120. //  Description:
  121. //        Update the state of the option box UI to reflect the option values.
  122. //
  123. //  Input Arguments:
  124. //      parent               - Top level parent layout of the option box UI.
  125. //                             Required so that UI object names can be 
  126. //                             successfully resolved.
  127. //
  128. //        forceFactorySettings - Whether the option values should be set to
  129. //                             default values.
  130. //
  131. //  Return Value:
  132. //      None.
  133. //
  134.  
  135. global proc boundarySetup( string $parent,
  136.                            int $forceFactorySettings,
  137.                            string $goToTool)
  138. {
  139.     //    Retrieve the option settings
  140.     //
  141.     setOptionVars($forceFactorySettings);
  142.     boundaryToolSetup( $forceFactorySettings, $goToTool );
  143.  
  144.     setParent $parent;
  145.  
  146.     //    Query the optionVar's and set the values into the controls.
  147.  
  148.     // Query the optionVar's and set the values into the controls
  149.     //
  150.     int $order = `optionVar -query boundaryOrder`;
  151.     int $insist = `optionVar -query boundaryInsist`;
  152.     int $partial = `optionVar -query boundaryPartial`;
  153.     int $polys = `optionVar -query boundaryPolys`;
  154.     if( ! `isTrue "SurfaceUIExists"` ) $polys = 1;
  155.  
  156.     int $useGlobal = `optionVar -query boundaryUseGlobal`;
  157.     float $tolerance = `optionVar -query boundaryTolerance`;
  158.  
  159.     radioButtonGrp -edit -select ($order+1) orderRadio;
  160.     radioButtonGrp -edit -select ($insist+1) insistRadio;
  161.     radioButtonGrp -edit -select ($partial+1) partialRadio;
  162.     radioButtonGrp -edit -select (2 - $useGlobal) useGlobalRadio;
  163.     floatSliderGrp -edit -value $tolerance toleranceFloat;
  164.  
  165.     // set polygons | Nurbs option.
  166.     //
  167.     if( `isTrue "SurfaceUIExists"` ) {
  168.         if( (3 == $polys) && ! `isTrue "SubdivUIExists"` ) {
  169.             $polys = 2;
  170.         }
  171.         radioButtonGrp -edit -select ($polys+1) outputPolyRadioButtonGrp;
  172.     }
  173.     switch( $polys ) {
  174.       case 0:
  175.       default:
  176.         tabLayout -e -st polyOptionsNo polyOptions;
  177.         break;
  178.       case 1:
  179.         tabLayout -e -st polyOptionsOK polyOptions;
  180.         break;
  181.       case 2:
  182.         tabLayout -e -st polyOptionsSubdiv polyOptions;
  183.         break;
  184.       case 3:
  185.         tabLayout -e -st polyOptionsBezier polyOptions;
  186.         break;
  187.     }
  188.     nurbsToPolySetup( $parent, $forceFactorySettings );
  189.     nurbsToSubdivSetup( $parent, $forceFactorySettings );
  190.     boundaryVisibility( $parent, $useGlobal, $insist, $goToTool );
  191.  
  192.     if( "" != $goToTool ) { 
  193.         checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool`
  194.           scriptToolExtraWidget;
  195.         checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool`
  196.           scriptToolExtraWidget;
  197.         checkBoxGrp -e -v1 (4 == `optionVar -q boundaryAutoEdgeCount`)
  198.           scriptToolExtraWidget2;
  199.     }
  200. }
  201.  
  202. //
  203. //  Procedure Name:
  204. //      boundaryCallback
  205. //
  206. //  Description:
  207. //        Update the option values with the current state of the option box UI.
  208. //
  209. //  Input Arguments:
  210. //      parent - Top level parent layout of the option box UI.  Required so
  211. //               that UI object names can be successfully resolved.
  212. //
  213. //        doIt   - Whether the command should execute.
  214. //
  215. //  Return Value:
  216. //      None.
  217. //
  218.  
  219. global proc boundaryCallback( string $parent, int $doIt, string $goToTool )
  220. {
  221.     if( "" != $goToTool ) {
  222.         optionVar -iv boundaryEuc `scriptCtx -q -euc $goToTool`;
  223.         optionVar -iv boundaryLac `scriptCtx -q -lac $goToTool`;
  224.     }
  225.     setParent $parent;
  226.  
  227.     // Set the optionVar's from the current control values, and then perform 
  228.     // the command
  229.     //
  230.     int $order = `radioButtonGrp -q -select orderRadio` - 1;
  231.     int $insist = `radioButtonGrp -q -select insistRadio` - 1;
  232.     int $partial = `radioButtonGrp -q -select partialRadio` - 1;
  233.     int $useGlobal = 2 - `radioButtonGrp -q -select useGlobalRadio`;
  234.     float $tolerance = `floatSliderGrp -q -value toleranceFloat`;
  235.  
  236.     optionVar -intValue boundaryOrder $order;
  237.     optionVar -intValue boundaryInsist $insist;
  238.     optionVar -intValue boundaryPartial $partial;
  239.     optionVar -intValue boundaryUseGlobal $useGlobal;
  240.     optionVar -floatValue boundaryTolerance $tolerance;
  241.  
  242.     if( `isTrue "SurfaceUIExists"` ) {
  243.         int $polys = `radioButtonGrp -q -select outputPolyRadioButtonGrp`;
  244.         if( (3 == $polys) && ! `isTrue "SubdivUIExists"` ) {
  245.             $polys = 4;
  246.         }
  247.         optionVar -intValue boundaryPolys ($polys-1);
  248.     }
  249.  
  250.     nurbsToPolyCallback( $parent, 0 );
  251.     nurbsToSubdivCallback( $parent, 0 );
  252.  
  253.     if( 1 == $doIt ) {
  254.         performBoundary( 0, $goToTool ); 
  255.         string $tmpCmd = "performBoundary( 0, \"" + $goToTool + "\")";
  256.         addToRecentCommandQueue $tmpCmd "Boundary";
  257.     }
  258.     else if( $doIt ) {
  259.         setToolTo $goToTool;
  260.     }
  261. }
  262.  
  263. //
  264. //  Procedure Name:
  265. //      boundaryOptions
  266. //
  267. //  Description:
  268. //        Construct the option box UI.  Involves accessing the standard option
  269. //        box and customizing the UI accordingly.
  270. //
  271. //  Input Arguments:
  272. //      None.
  273. //
  274. //  Return Value:
  275. //      None.
  276. //
  277.  
  278. proc boundaryOptions( int $inTheTool, string $goToTool )
  279. {
  280.     //    Name of the command for this option box.
  281.     //
  282.     string $commandName = "boundary";
  283.  
  284.     //    Build the option box actions.
  285.     //
  286.     string $callback = ($commandName + "Callback");
  287.     string $setup = ($commandName + "Setup");
  288.  
  289.     //    Step 1:  Get the option box.
  290.     //    ============================
  291.     global string $gOptionBoxActionToolItem;
  292.     $gOptionBoxActionToolItem = "modelWithToolBoundary";
  293.     global string $gOptionBoxActionToolItemCB;
  294.     $gOptionBoxActionToolItemCB = "boundaryToolScript 3";
  295.  
  296.     string $layout = getOptionBox();
  297.     setParent $layout;
  298.     
  299.     //    Step 2:  Pass the command name to the option box.
  300.     //    =================================================
  301.     setOptionBoxCommandName($commandName);
  302.     
  303.     //    Step 3:  Activate the default UI template.
  304.     //    ==========================================
  305.     setUITemplate -pushTemplate DefaultTemplate;
  306.  
  307.     //    Step 4: Create option box contents.
  308.     //    ===================================
  309.     
  310.     //    Turn on the wait cursor.
  311.     //
  312.     waitCursor -state 1;
  313.  
  314.     tabLayout -scr true -tv false;
  315.     
  316.     string $parent = `columnLayout -adjustableColumn 1`;
  317.     
  318.     radioButtonGrp -nrb 2 -l "Curve Ordering"
  319.         -l1 "Automatic"
  320.         -l2 "As Selected"
  321.         orderRadio;
  322.         
  323.     radioButtonGrp -nrb 2 -l "Common End Points"
  324.         -l1 "Optional"
  325.         -l2 "Required"
  326.         insistRadio;
  327.         
  328.     radioButtonGrp
  329.         -numberOfRadioButtons 2
  330.         -label "End Point Tolerance"
  331.         -label1 "Global"
  332.         -label2 "Local"
  333.         useGlobalRadio;
  334.         
  335.     floatSliderGrp -label "Tolerance" 
  336.         -min 0.001 -max 1.0 -fmn 0.00001 -fmx 1000.0
  337.         toleranceFloat;
  338.  
  339.     separator;
  340.  
  341.     radioButtonGrp -numberOfRadioButtons 2
  342.         -label "Curve Range"
  343.         -label1 "Complete"
  344.         -label2 "Partial"
  345.         partialRadio;
  346.  
  347.  
  348.     // Set the tolerance radio button up so that when "Global" is
  349.     // selected, then the local tolerance slider is disabled.
  350.     // When "Local" is selected then the local tolerance slider is enabled.
  351.     //
  352.     radioButtonGrp -edit
  353.         -cc1 ("boundaryVisibility " + $parent + " 1 -1 \"" + $goToTool + "\"")
  354.         -cc2 ("boundaryVisibility " + $parent + " 0 -1 \"" + $goToTool + "\"")
  355.         useGlobalRadio;
  356.  
  357.     // Set the layout that contains the number of spans slider and 
  358.     // the degree slider so that only displays stuff when the type is Uniform.
  359.     //
  360.     radioButtonGrp -edit
  361.         -cc2 ("boundaryVisibility " + $parent + " -1 1 \"" + $goToTool + "\"")
  362.         -cc1 ("boundaryVisibility " + $parent + " -1 0 \"" + $goToTool + "\"")
  363.         insistRadio;
  364.  
  365.     separator ;
  366.  
  367.     // output Geometry
  368.     //
  369.     if( `isTrue "SubdivUIExists"` ) {
  370.         radioButtonGrp -numberOfRadioButtons 4
  371.           -label "Output Geometry"
  372.           -label1 "Nurbs"
  373.           -label2 "Polygons"
  374.           -label3 "Subdiv"
  375.           -label4 "Bezier"
  376.           -cc1 "tabLayout -e -st polyOptionsNo polyOptions"
  377.           -cc2 "tabLayout -e -st polyOptionsOK polyOptions"
  378.           -cc3 "tabLayout -e -st polyOptionsSubdiv polyOptions"
  379.           -cc4 "tabLayout -e -st polyOptionsBezier polyOptions"
  380.           outputPolyRadioButtonGrp;
  381.     }
  382.     else if( `isTrue "SurfaceUIExists"` ) {
  383.         radioButtonGrp -nrb 3
  384.           -label "Output Geometry"
  385.           -label1 "Nurbs"
  386.           -label2 "Polygons"
  387.           -label3 "Bezier"
  388.           -cc1 "tabLayout -e -st polyOptionsNo polyOptions"
  389.           -cc2 "tabLayout -e -st polyOptionsOK polyOptions"
  390.           -cc3 "tabLayout -e -st polyOptionsBezier polyOptions"
  391.           outputPolyRadioButtonGrp;
  392.     }
  393.  
  394.     tabLayout -tabsVisible false polyOptions;
  395.       string $par = `columnLayout polyOptionsOK`;
  396.         nurbsToPolyAddOptions $par;
  397.         setParent ..;
  398.       columnLayout polyOptionsNo;
  399.       setParent ..;
  400.       columnLayout polyOptionsSubdiv;
  401.         nurbsToSubdivAddOptions $par;
  402.       setParent ..;
  403.       columnLayout polyOptionsBezier;
  404.       setParent ..;
  405.    setParent ..;
  406.  
  407.     if( $inTheTool ) {
  408.         separator;
  409.         checkBoxGrp -ncb 2 -l "Tool Behavior"
  410.           -l1 "Exit on Completion"
  411.           -v1 off
  412.           -on1 ("scriptCtx -e -euc true " + $goToTool)
  413.           -of1 ("scriptCtx -e -euc false " + $goToTool)
  414.  
  415.           -l2 "Auto Completion"
  416.           -v2 on
  417.           -on2 ("boundaryAutoComplete 1 " +
  418.                 "\"" + $goToTool + "\";" +
  419.                 "boundaryVisibility " + $parent + " 1 -1 \"" +
  420.                 $goToTool + "\"")
  421.           -of2 ("boundaryAutoComplete 0 " +
  422.                 "\"" + $goToTool + "\";" +
  423.                 "boundaryVisibility " + $parent + " 1 -1 \"" +
  424.                 $goToTool + "\"")
  425.           scriptToolExtraWidget;
  426.  
  427.         checkBoxGrp -ncb 1 -l ""
  428.           -l1 "4 Boundary Curves"
  429.           -v1 off
  430.           -on1 ("boundary4curves 4 " + $goToTool +
  431.                 "; optionVar -iv boundaryAutoEdgeCount 4")
  432.           -of1 ("boundary4curves 3 " + $goToTool +
  433.                 "; optionVar -iv boundaryAutoEdgeCount 3")
  434.           scriptToolExtraWidget2;
  435.     }
  436.  
  437.     //    Turn off the wait cursor.
  438.     //
  439.     waitCursor -state 0;
  440.     
  441.     //    Step 5: Deactivate the default UI template.
  442.     //  ===========================================
  443.     //
  444.     setUITemplate -popTemplate;
  445.  
  446.     //    Step 6: Customize the buttons.  
  447.     //    ==============================
  448.  
  449.     //    'Apply' button.
  450.     //
  451.     string $applyBtn = getOptionBoxApplyBtn();
  452.     if( $inTheTool ) {
  453.         button -edit -l "Boundary Tool"
  454.             -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" )
  455.             $applyBtn;
  456.     }
  457.     else {
  458.         button -edit -l "Boundary"
  459.             -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"" )
  460.             $applyBtn;
  461.     }
  462.  
  463.     //    'Save' button.
  464.     //
  465.     string $saveBtn = getOptionBoxSaveBtn();
  466.     button -edit 
  467.         -command ($callback + " " + $parent + " 0 \"" +
  468.                   $goToTool + "\"; hideOptionBox")
  469.         $saveBtn;
  470.  
  471.     //    'Reset' button.
  472.     //
  473.     string $resetBtn = getOptionBoxResetBtn();
  474.     button -edit 
  475.         -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"")
  476.         $resetBtn;
  477.  
  478.     //    Step 7: Set the option box title.
  479.     //    =================================
  480.     //
  481.     if( $inTheTool ) {
  482.         setOptionBoxTitle("Boundary Tool Options");
  483.     }
  484.     else {
  485.         setOptionBoxTitle("Boundary Options");
  486.     }
  487.  
  488.     //    Step 8: Customize the 'Help' menu item text.
  489.     //    ============================================
  490.     //
  491.     setOptionBoxHelpTag( "Boundary" );
  492.  
  493.     //    Step 9: Set the current values of the option box.
  494.     //    =================================================
  495.     //
  496.     eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\"");
  497.     
  498.     //    Step 10: Show the option box.
  499.     //    =============================
  500.     //
  501.     showOptionBox();
  502. }
  503.  
  504. //
  505. //  Procedure Name:
  506. //      boundaryHelp
  507. //
  508. //  Description:
  509. //        Return a short description about this command.
  510. //
  511. //  Input Arguments:
  512. //      None.
  513. //
  514. //  Return Value:
  515. //      string.
  516. //
  517.  
  518. proc string boundaryHelp()
  519. {
  520.     return 
  521.     "  Command: Boundary  - create boundary surface from 3 or 4 curves.\n" +
  522.     "Selection: curves, surface isoparms, curve on surface, surface edges";    
  523. }
  524.  
  525. //
  526. //  Procedure Name:
  527. //      assembleCmd
  528. //
  529. //  Description:
  530. //        Construct the command that will apply the option box values.
  531. //
  532. //  Input Arguments:
  533. //      None.
  534. //
  535. //  Return Value:
  536. //      None.
  537. //
  538. proc string assembleCmd()
  539. {
  540.     string $cmd = "performBoundaryPreset";
  541.  
  542.     setOptionVars(false);
  543.  
  544.     int $doHistory = `constructionHistory -q -tgl`;
  545.     int $order = `optionVar -q boundaryOrder`;
  546.     int $insist = `optionVar -q boundaryInsist`;
  547.     int $partial = `optionVar -q boundaryPartial`;
  548.     int $polys = `optionVar -q boundaryPolys`;
  549.     if( ! `isTrue "SurfaceUIExists"` ) $polys = 1;
  550.     int $useGlobal = `optionVar -q boundaryUseGlobal`;
  551.     float $globalTol = `optionVar -q positionalTolerance`;
  552.     float $localTol = `optionVar -q boundaryTolerance`;
  553.  
  554.     $cmd = ( $cmd + " " +
  555.              $doHistory + " " +
  556.              $order + " " +
  557.              $insist + " " +
  558.              $partial + " " +
  559.              $polys + " " +
  560.              $useGlobal + " " +
  561.              $globalTol + " " +
  562.              $localTol );
  563.     return $cmd;
  564. }
  565.  
  566. //
  567. //  Procedure Name:
  568. //      performBoundary
  569. //
  570. //  Description:
  571. //        Perform the boundary command using the corresponding 
  572. //        option values.  This procedure will also show the option box
  573. //        window if necessary as well as construct the command string
  574. //        that will invoke the boundary command with the current
  575. //        option box values.
  576. //
  577. //  Input Arguments:
  578. //      0 - Execute the command.
  579. //      1 - Show the option box dialog.
  580. //      2 - Return the command.
  581. //      3 - Show the tool option box dialog.
  582. //
  583. //  Return Value:
  584. //      None.
  585. //
  586.  
  587. global proc string performBoundary( int $action, string $goToTool )
  588. {
  589.     int $inTheTool = false;
  590.     if( 3 == $action ) {
  591.         $action = 1;
  592.         $inTheTool = true;
  593.     }
  594.  
  595.     string $cmd = "";
  596.     switch ($action) {
  597.       case 0:
  598.         setOptionVars(false);
  599.         $cmd = `assembleCmd`;
  600.         eval($cmd);
  601.         break;
  602.       case 1:
  603.         boundaryOptions( $inTheTool, $goToTool );
  604.         break;
  605.  
  606.       case 2:
  607.         setOptionVars (false);
  608.         $cmd = `assembleCmd`;
  609.         break;
  610.     }
  611.     return $cmd;
  612. }
  613.  
  614.